local addonName, addon = ...
-- #####################################################################################################################
local frameName = "角色";
local subFrame = CreateFrame("Frame", frameName, nil, InterfaceOptionsFramePanelContainer, nil)
subFrame:Hide();
-- #####################################################################################################################
local category, layout = addon:InterfaceOptions_AddSubCategory(subFrame, subFrame:GetName())
-- #####################################################################################################################
subFrame:RegisterEvent("ADDON_LOADED")
subFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
subFrame:SetScript("OnEvent", function(self, event, loadedAddon)
    if event == "ADDON_LOADED" and loadedAddon == addonName then
        self:UnregisterEvent("ADDON_LOADED")
    elseif event == "PLAYER_ENTERING_WORLD" then
        self:UnregisterEvent("PLAYER_ENTERING_WORLD")
    end
end)
-- #####################################################################################################################
subFrame:SetScript("OnShow", function(frame)
    --------------------------------------------------------------------------------------------------------------------------
    local title = subFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
    title:SetPoint("TOPLEFT", 16, -16)
    title:SetText("角色")
    --------------------------------------------------------------------------------------------------------------------------
    local player = addon:newCheckbox(subFrame, "测试角色API", "测试角色API", function(self, value)
        -- ======================================================================
        local playerName = UnitName("player")
        local playerName2 = GetUnitName("player", true)
        print("playerName = ", playerName)
        print("playerName2 = ", playerName2)
        local hp = UnitHealth("player");
        local mp = UnitPower("player");
        print("hp = ", hp);
        print("mp = ", mp);
        -- ======================================================================
        -- UnitClass("player"):职业
        local myClass = select(2, UnitClass("player"))
        local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[myClass]
        print("myClass = ", myClass)
        print("color = ", color)
        -- ======================================================================
        -- 判断是否是队长
        local isGroupLeader = UnitIsGroupLeader("player")
        print("判断是否是队长isGroupLeader = ", isGroupLeader)
        -- ======================================================================
        -- 获取玩家/宠物的指定专精的信息
        -- specID = GetSpecialization()
        local specID = GetSpecialization();
        print("玩家专精 specID = ", specID) -- NQ=1 FQ=2 CJQ=3
        -- FIXME(ljs):下面代码无效?
        -- id, name, description, icon, background, role, primaryStat = GetSpecializationInfo(specID, isInspect, isPet, "inspectTarget", gender)
        local specializationInfo = { GetSpecializationInfo(specID, true, false, "inspectTarget") }
        addon:print_table(specializationInfo)
        local id, name, description, icon, background, role, class = GetSpecializationInfoByID(specID)
        local currentSpecializationInfo = { GetSpecializationInfoByID(specID) }
        addon:print_table(currentSpecializationInfo)
        -- ======================================================================
        -- 获取速度
        -- speed, groundSpeed, flightSpeed, swimSpeed = GetUnitSpeed(unit)
        local unitSpeedInfo = { GetUnitSpeed("player") };
        addon:print_table(unitSpeedInfo)
        print("unitSpeedInfo.speed = ", unitSpeedInfo[1])
        print("地面速度unitSpeedInfo.groundSpeed = ", unitSpeedInfo[2])
        print("飞行速度unitSpeedInfo.flightSpeed = ", unitSpeedInfo[3])
        print("游泳速度unitSpeedInfo.swimSpeed = ", unitSpeedInfo[4])
        -- ======================================================================
        -- 返回自己的坐标
        -- unitX, unitY = GetPlayerMapPosition("unit")
        local x, y, z = GetPlayerMapPosition("player")
        print("x=", x, "y=", y, "z=", z)
    end)
    player:SetPoint("TOPLEFT", title, "BOTTOMLEFT", -2, -16)
    --------------------------------------------------------------------------------------------------------------------------
end)
-- #####################################################################################################################